package cn.jekun.shop.web.action;

import javax.annotation.Resource;

import net.sf.json.JSONObject;
import cn.jekun.component.base.bean.ErrorMsg;
import cn.jekun.component.base.exceptions.BusinessException;
import cn.jekun.component.core.service.gen.ErpMerchandiseTypeService;
import cn.jekun.shop.common.service.ShopBaseAction;
import cn.jekun.shop.common.service.ShopService;

/**
 * 商品类型
 * 
 * @author twj
 * 
 */
@SuppressWarnings("serial")
public class GoodsTypeAction extends ShopBaseAction {
	@Resource(name = ErpMerchandiseTypeService.BEAN_NAME)
	protected ErpMerchandiseTypeService erpMerchandiseTypeService;
	@Resource(name = ShopService.BEAN_NAME)
	ShopService shopService;
	/**
	 * 展示所有商品类型
	 * 
	 * @return
	 */
	public String showTypes() {
		JSONObject jsonObject = new JSONObject();
		try {
			String shopId = this.request.getParameter("shopId");
			String parentId = this.request.getParameter("parentId");
			jsonObject = shopService.shopGoodsType(parentId,shopId);
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	
	
	/**
	 * 展示所有商品类型
	 * 
	 * @return
	 */
	public String queryAllMerchandiseTypelistByShopId() {
		JSONObject jsonObject = new JSONObject();
		try {
			String shopId = this.request.getParameter("shopId");
			jsonObject = shopService.queryAllMerchandiseTypelistByShopId(shopId);
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	

}
